﻿<prism:VisualStateAwarePage 
    x:Name="pageRoot"
    x:Class="Sumc.Client.ModernUI.Views.HomePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Sumc.Client.ModernUI.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prism="using:Microsoft.Practices.Prism.StoreApps"
    xmlns:behaviors="using:Sumc.Client.ModernUI.Attachements"
    mc:Ignorable="d"
    prism:ViewModelLocator.AutoWireViewModel="True">

    <prism:VisualStateAwarePage.Resources>
        <DataTemplate x:Key="MainStopItemTemplate">
            <Grid Width="290"
                  Height="130"
                  Margin="1"
                  Background="{StaticResource DefaultItemBackground}"
                  behaviors:Behaviours.PointerPressed="{Binding DataContext.GoToStop, ElementName=pageRoot}"
                  behaviors:Behaviours.PointerPressedParameter="{Binding Name}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock FontSize="18"
                           FontWeight="Light"
                           HorizontalAlignment="Left"
                           Margin="25,20,25,10"
                           Padding="0"
                           Text="{Binding Name}"
                           TextTrimming="WordEllipsis"
                           Foreground="{StaticResource DefaultWhiteBrush}"
                           Grid.Row="0"/>
                <TextBlock FontSize="14"
                           FontWeight="Light"
                           HorizontalAlignment="Left"
                           Margin="25,0,25,0"
                           Padding="0"
                           Foreground="{StaticResource DefaultDarkBrush}"
                           x:Uid="HomePageTextBlockStopTransports"
                           Grid.Row="1"/>
                <TextBlock FontSize="18"
                           FontWeight="Light"
                           HorizontalAlignment="Left"
                           Margin="25,0,25,10"
                           Padding="0"
                           TextTrimming="WordEllipsis"
                           TextWrapping="Wrap"
                           LineHeight="19"
                           LineStackingStrategy="BaselineToBaseline"
                           Foreground="{StaticResource DefaultWhiteBrush}"
                           Text="{Binding TransportNumbers, Converter={StaticResource EnumerationToTextConverter}}"
                           Grid.Row="2"/>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="NewsItemTemplate">
            <Grid Width="290"
                  Height="130"
                  Margin="1"
                  Background="{StaticResource DefaultItemBackground}"
                  behaviors:Behaviours.PointerPressed="{Binding DataContext.GoToNews, ElementName=pageRoot}"
                  behaviors:Behaviours.PointerPressedParameter="{Binding}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock FontSize="18"
                           FontWeight="Light"
                           HorizontalAlignment="Left"
                           Margin="25,20,25,10"
                           Padding="0"
                           Height="50"
                           Text="{Binding Title, Converter={StaticResource UppercaseConverter}}"
                           TextTrimming="WordEllipsis"
                           TextWrapping="Wrap"
                           Foreground="{StaticResource DefaultWhiteBrush}"
                           Grid.Row="0"/>
                <TextBlock FontSize="14"
                           FontWeight="Light"
                           HorizontalAlignment="Left"
                           Margin="25,0,25,0"
                           Padding="0"
                           Foreground="{StaticResource DefaultDarkBrush}"
                           Text="{Binding Date}"
                           Grid.Row="1"/>
            </Grid>
        </DataTemplate>
    </prism:VisualStateAwarePage.Resources>

    <Grid x:Name="MainGrid"
          Style="{StaticResource LayoutRootStyle}" 
          Background="{StaticResource Background}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <ScrollViewer x:Name="MainScrollViewer"
                      Grid.RowSpan="2"
                      Padding="0,170,0,50"
                      HorizontalScrollBarVisibility="Auto"
                      HorizontalScrollMode="Enabled"
                      VerticalScrollMode="Disabled"
                      VerticalScrollBarVisibility="Disabled"
                      MaxZoomFactor="1"
                      MinZoomFactor="0.5">
            <StackPanel x:Name="ResultsStackPanel"
                        Orientation="Horizontal"
                        Margin="115,0,120,0">

                <Grid Visibility="{Binding News, Converter={StaticResource NullToVisibilityConverter}}"
                      Margin="0,0,100,0"
                      Grid.RowSpan="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock FontSize="18"
                               x:Uid="HomePageTextBlockNews"
                               Margin="5,0,0,30"
                               Foreground="{StaticResource DefaultWhiteBrush}"/>
                    <ListView Grid.Row="1"
                              Grid.Column="0"
                              ItemsSource="{Binding News, Mode=OneWay}"
                              Height="{Binding ElementName=MainStopsGridView, Path=Height}"
                              ItemTemplate="{StaticResource NewsItemTemplate}"
                              Margin="0,0,0,70"
                              SelectionMode="None" />
                </Grid>

                <Grid x:Name="MainGridViewer"
                      Visibility="{Binding MainStops, Converter={StaticResource NullToVisibilityConverter}}"
                      Grid.RowSpan="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock x:Name="CategoryTextBlock"
                               FontSize="18"
                               x:Uid="HomePageTextBlockMainStops"
                               Margin="5,0,0,30"
                               Foreground="{StaticResource DefaultWhiteBrush}"/>
                    <GridView x:Name="MainStopsGridView"
                              Grid.Row="1"
                              Grid.Column="0"
                              ItemsSource="{Binding MainStops, Mode=OneWay}"
                              ItemTemplate="{StaticResource MainStopItemTemplate}"
                              SelectionMode="None"
                              Style="{StaticResource GridViewWithoutScroll}" >
                    </GridView>
                </Grid>

            </StackPanel>
        </ScrollViewer>
        
        <!--Snap-->
        <ScrollViewer x:Name="SnapMainScrollViewer"
                      Grid.RowSpan="2"
                      Padding="0,170,0,0"
                      HorizontalScrollBarVisibility="Disabled"
                      HorizontalScrollMode="Disabled"
                      VerticalScrollMode="Enabled"
                      VerticalScrollBarVisibility="Auto"
                      Visibility="Collapsed"
                      MaxZoomFactor="1"
                      MinZoomFactor="0.5">
            <StackPanel Orientation="Vertical">
                <Grid Visibility="{Binding News, Converter={StaticResource NullToVisibilityConverter}}"
                      Margin="0,0,0,20"
                      Grid.RowSpan="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock FontSize="18"
                               x:Uid="HomePageTextBlockNews"
                               Margin="5,0,0,30"
                               Foreground="{StaticResource DefaultWhiteBrush}"/>

                    <ListView Grid.Row="1"
                              Grid.Column="0"
                              Padding="5,0,0,0"
                              ItemsSource="{Binding News, Mode=OneWay}"
                              ItemTemplate="{StaticResource NewsItemTemplate}"
                              SelectionMode="None"
                              Style="{StaticResource ListViewWithoutScroller}" />
                </Grid>
                
                <Grid Visibility="{Binding MainStops, Converter={StaticResource NullToVisibilityConverter}}"
                      Grid.RowSpan="2">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <TextBlock FontSize="18"
                               x:Uid="HomePageTextBlockMainStops"
                               Margin="5,0,0,30"
                               Foreground="{StaticResource DefaultWhiteBrush}"/>

                    <ListView x:Name="MainStopsListView"
                              Grid.Row="1"
                              Grid.Column="0"
                              Padding="5,0,0,0"
                              ItemsSource="{Binding MainStops, Mode=OneWay}"
                              ItemTemplate="{StaticResource MainStopItemTemplate}"
                              SelectionMode="None"
                              Style="{StaticResource ListViewWithoutScroller}" />
                </Grid>

            </StackPanel>
        </ScrollViewer>
        
        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton"
                    Command="{Binding GoBack}"
                    Style="{StaticResource BackButtonStyle}" />
            <Image Grid.Column="1" Source="ms-appx:///Assets/MainLogo.png"
                   Stretch="None"
                   HorizontalAlignment="Left" NineGrid="0" VerticalAlignment="Top" Margin="0,50,0,0"/>
        </Grid>

        <ProgressBar IsIndeterminate="{Binding LoadingData}"
                     Visibility="{Binding LoadingData, Converter={StaticResource BooleanToVisibilityConverter}}"
                     Style="{StaticResource PageProgressBar}"
                     Grid.Row="1" />

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MainScrollViewer"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnapMainScrollViewer"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton"
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</prism:VisualStateAwarePage>
